#include <stdio.h>
#include <stdlib.h>
#include "aimage.h"
#include "aimage_utils.h"
#include "aimage_ppm.h"

int main( int argc, char *argv[] )
{
	AIMAGE image;
	float rg, gg, bg;

	if ( argc != 4 && argc != 5 )
	{
		fprintf(stderr, "%s rg gg bg [in_file]\n", argv[0] );
		exit( 1 );
	}

	rg = atof( argv[1] );
	if ( rg <= 0 )
	{
		fprintf(stderr, "%s red gamma must be greater than 0\n",
			argv[0] );
		exit( 1 );
	}
	gg = atof( argv[2] );
	if ( gg <= 0 )
	{
		fprintf(stderr, "%s green gamma must be greater than 0\n",
			argv[0] );
		exit( 1 );
	}
	bg = atof( argv[3] );
	if ( bg <= 0 )
	{
		fprintf(stderr, "%s green gamma must be greater than 0\n",
			argv[0] );
		exit( 1 );
	}

	if ( argc == 5 )
	{
		fprintf(stderr,"trigamma reading from %s, %g %g %g\n", 
			argv[4], rg, gg, bg );
		AIMAGE_PPM_UTILS::load( image, argv[4] );
	}
	else
	{
		fprintf(stderr,"trigamma reading from stdin, %g %g %g\n", 
			rg, gg, bg );
		AIMAGE_PPM_UTILS::load( image, "stdin" );
	}

	fprintf(stderr,"trigamma done read file\n");
	AIU::gamma( image, rg, gg, bg );
	fprintf(stderr,"trigamma writing file\n");

	AIMAGE_PPM_UTILS::save( image, "stdout" );
}

